package com.ThreadDemo;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: FENGYiMing
 * @Date: 2024/04/01/15:51
 * @Description:
 */
public class Thead02 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new T());

        for (int i = 1; i <= 10; i++) {
            System.out.println("hi" + i);
            Thread.sleep(1000);
            if (i == 5) {
                thread.start();//启动子线程
                //子线程开启插队，主线程会让子线程先执行
                thread.join();
            }
        }
    }
}

class T implements Runnable {
    @Override
    public void run() {
        for (int i = 1; i <= 10; i++) {
            System.out.println("hello" + i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
